package com.itheima.day15.work5;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket  ss=new ServerSocket(10007);
        UUID uuid = UUID.randomUUID();
        BufferedWriter bw=new BufferedWriter(new FileWriter("a.txt"));
        ThreadPoolExecutor pool=new ThreadPoolExecutor(
                3,
                10,30, TimeUnit.SECONDS,new ArrayBlockingQueue<>(5), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        while (true) {
            Socket accept = ss.accept();
            pool.submit(new ServerThread(accept,bw));
        }

       /* BufferedReader br=new BufferedReader(new InputStreamReader(accept.getInputStream()));
        BufferedWriter bw=new BufferedWriter(new FileWriter("a.txt"));
        String  s;
        System.out.print("服务器端接受数据：");
        while ((s=br.readLine())!=null){
            System.out.println(s);
            bw.write(s);
            bw.newLine();
            bw.flush();
        }

        BufferedWriter bw1=new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw1.write("上传成功");
        bw1.newLine();
        bw1.flush();

        accept.shutdownOutput();

        br.close();
        bw.close();
        bw1.close();
        ss.close();*/
    }
}
